package com.jiazhong.shopping.servlets;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Description:当一个类继承HttpServlet后，该类就成了一个Servlet类
 * Servlet注册的方式有两种:
 *  1.在web.xml文件中配置(不建议)
 *  2.使用注解配置
 * Servlet中要重写两个方法：
 *  1.doGet方法:用于接收Get请求
 *  2.doPost方法:用于接收post请求
 */
@WebServlet("/demo.do")
public class ServletDemo extends HttpServlet {
    /**
     * 用于接收客户端的Get请求
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("执行doGet方法....");
    }

    /**
     * 用于接收客户端的Post请求
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("执行doPost方法....");
    }

    /**
     * 服务方法，该方法可以接收任意请求
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("执行请求....");
    }
}